/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package SessionBeans;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.ejb.Stateless;

/**
 *
 * @author BELALOUACHE
 */
@Stateless
public class EuroConvertor implements EuroConvertorLocal {
 //enum Symbol {EUR, USD, JPY, GBP, CAD, AUD,CHF, RUB,CYN, ZAR, MXN}
 Map<String, String> devises;
 String currenDevise ;
    // Combien de f rancs f a i t un euro
private static final double UNEUROENFRANC = 6.55957 ;
private static final double UNEUROENUSD = 1.32705 ;
private static final double UNEUROENCAD = 1.32420 ;
private static final double UNEUROENGBP = 0.836202;
private static final double UNEUROENCYN = 8.36202 ;
private static final double UNEUROENCHF = 1.20516;
private static final double UNEUROENJPY = 109.276;
private static final double UNEUROENZAR = 10.1932;
private static final double UNEUROENMXN = 16.9200;
private static final double UNEUROENAUD = 1.26863 ;
private static final double UNEUROENRUB = 38.8614;


public double euroToFranc (float montantEnFranc) {
    return montantEnFranc / UNEUROENFRANC;
}
    @Override
public void ejbCreate ( ) {
  currenDevise="EUR";
  devises=new HashMap<String, String>();
  devises.put("EUR", "Euro");
  devises.put("USD", "Dollar Americain");
  devises.put("CAD", "Dollar Canadien");
  devises.put("GBP", "British Pound");
  devises.put("CHF", "Swiss Franc");
  devises.put("CYN", "Yuan Chinois");
  devises.put("JPY", "Yen Japonais");
  devises.put("MXN", "Peisso Mexicain");
  devises.put("ZAR", "Rand Sud-Africain");
}


    @Override
    public Double convertToEuro(double amount, String currencySymbol) {
        Double total=0.0;
        switch (currencySymbol){
             case "EUR" :
            total=amount/1; break;
            case "USD" :
            total=amount/UNEUROENUSD; break;
            case "GBP":
            total=amount/UNEUROENGBP; break;
            case "CAD" :
            total=amount/UNEUROENCAD; break;
            case "CYN":
            total=amount/UNEUROENCYN; break;
            case "JPY" :
            total=amount/UNEUROENJPY; break;
            case "CHF":
            total=amount/UNEUROENCHF; break;
            case "MXN" :
            total=amount/UNEUROENMXN; break;
            case "AUD":
            total=amount/UNEUROENAUD; break;
            case "RUB" :
            total=amount/UNEUROENRUB; break;
            case "ZAR":
            total=amount/UNEUROENZAR; break;
    }
        return total;
    }

    @Override
    public Double convertFronEuro(double amount, String currencySymbol) {
        Double total=0.0;
        switch (currencySymbol){
            case "USD" :
            total=amount*UNEUROENUSD; break;
            case "GBP":
            total=amount*UNEUROENGBP; break;
            case "CAD" :
            total=amount*UNEUROENCAD; break;
            case "CYN":
            total=amount*UNEUROENCYN; break;
            case "JPY" :
            total=amount*UNEUROENJPY; break;
            case "CHF":
            total=amount*UNEUROENCHF; break;
            case "MXN" :
            total=amount*UNEUROENMXN; break;
            case "AUD":
            total=amount*UNEUROENAUD; break;
            case "RUB" :
            total=amount*UNEUROENRUB; break;
            case "ZAR":
            total=amount*UNEUROENZAR; break;
    }
        return total;
    }

    @Override
    public List<String> getCurrencySymbols() {
        return (List<String>) devises.keySet();
    }

    @Override
    public String getCurrencyRealName(String currencySymbol) {
        return devises.get(currencySymbol);
    }
 
}
